﻿Imports System.IO
Imports System.ComponentModel
Imports ajayumi.develop.win32.Transport.Wcf.Contracts

Public Class UploadFileCallback
    Implements ICallback

    Public Event UploadProgressChanged As ProgressChangedEventHandler
    Public Overridable Sub OnUploadProgressChanged(ByVal e As ProgressChangedEventArgs)
        If e IsNot Nothing Then
            RaiseEvent UploadProgressChanged(Me, e)
        End If
    End Sub

    Public Event UploadCompleted As AsyncCompletedEventHandler
    Public Overridable Sub OnUploadCompleted(ByVal e As AsyncCompletedEventArgs)
        If e IsNot Nothing Then
            RaiseEvent UploadCompleted(Me, e)
        End If
    End Sub


    Public Sub OnCompleted(ByVal transFileInfo As Contracts.TransFileInfo) Implements Contracts.ICallback.OnCompleted
        Try
            Me.OnUploadCompleted(New AsyncCompletedEventArgs(Nothing, False, transFileInfo))
        Catch ex As Exception
            Me.OnUploadCompleted(New AsyncCompletedEventArgs(ex, True, transFileInfo))
        End Try
    End Sub

    Public Sub OnProgressChanged(ByVal transFileInfo As Contracts.TransFileInfo) Implements Contracts.ICallback.OnProgressChanged
        Dim _progressPercentage As Single = CSng(transFileInfo.Position) / CSng(transFileInfo.FileLength) * 100D
        Me.OnUploadProgressChanged(New ProgressChangedEventArgs(CInt(_progressPercentage), transFileInfo))
    End Sub
End Class
